// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        nickname: cc.Label,
        score: cc.Node,
        avatar: cc.Sprite,
        bandage: cc.Sprite,
        no0: cc.SpriteFrame,
        no1: cc.SpriteFrame,
        no2: cc.SpriteFrame,
        no3: cc.SpriteFrame,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    setName (name) {
        this.nickname.string = name
    },
    setScore (score) {
        this.score.getComponent('labelFixed').setNumber(score, '¥')
    },
    setBandage (rank) {
        this.bandage.enabled = true
        this.bandage.spriteFrame = this['no' + rank]
    },
    loadAvatar (url) {
        let self = this
        cc.loader.load({
            url: url, type: 'png'
        }, (err, texture) => {
            if (err) console.error(err);
            this.avatar.spriteFrame = new cc.SpriteFrame(texture);
        });  
    },
    start () {

    },

    // update (dt) {},
});
